package com.micro.edu.rpc;

import com.micro.edu.dao.MicroAuthCodeDao;
import com.micro.edu.pojo.MicroAuthCode;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;

import java.util.Optional;

/**
 * @author Tyd
 * @date 2021/03/11 11:28
 */
@Service
public class MicroCodeRpc implements IMicroCodeRpc {

    @Autowired
    private MicroAuthCodeDao microAuthCodeDao;

    @Override
    public int validate(String email, String code) {
        MicroAuthCode microAuthCode = new MicroAuthCode();
        microAuthCode.setEmail(email);
        microAuthCode.setCode(code);
        Optional<MicroAuthCode> optional = microAuthCodeDao.findOne(Example.of(microAuthCode));
        if (optional.isEmpty()) {
            return 1;
        }
        return 0;
    }
}
